package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.AdminDao;
import com.pojo.AdminPojo;

public class LoadJcy extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		
		String message = "获取信息失败";
		String jcyName = "";
		String jcyTel = "";
		String jcyAddress = "";
		
		AdminPojo admin = new AdminPojo();
		AdminDao dao = new AdminDao();
		admin = dao.findByAdminName("admin");
		if (!admin.getJcyName().equals("")){
			message = "获取信息成功";
			jcyName = admin.getJcyName();
			jcyTel = admin.getJcyTel();
			jcyAddress = admin.getJcyAddress();
		}
		dao.closeAll();
		
        response.setContentType("text/plain");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		String json = "{\"status\":\""+message+"\",\"jcyName\":\""+jcyName+"\",\"jcyTel\":\""+jcyTel+"\",\"jcyAddress\":\""+jcyAddress+"\"}";
		out.println(json);
		out.flush();
        out.close();
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
